define(function (require, exports, module)
{
  var $ = require('jquery');
  require('json2');
  var k = require('kindeditor');
  var jxbaseinfo = require('jxbaseinfo');
  var jnkeditor = [];
  var jnk_config = {
    basePath: jxbaseinfo.path+'kindeditor/',
    uploadJson: jxbaseinfo.path+'jku/upload/',
    fileManagerJson: jxbaseinfo.path+'jku/fileManager/',
    allowFileManager: true,
    allowImageUpload: true,
    allowMediaUpload: true,
    items: [
      'source', '|', 'undo', 'redo', '|', 'preview', 'template', 'cut', 'copy', 'paste',
      'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
      'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
      'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
      'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
      'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image','multiimage',
      'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
      'anchor', 'link', 'unlink'],
    afterBlur: function ()
    {
      var self = this;
      self.sync();
    }
  };
  k.ready(function (K)
  {
    $("textarea").each(function ()
    {
      if (undefined == $(this).attr("jnk_id"))
        return true;

      if (undefined != $(this).attr("jnk_cfg"))
        jnk_config = $.extend(true, {}, jnk_config, JSON.parse($(this).attr("jnk_cfg")));
      $(this).attr("id", $(this).attr("jnk_id"));
      jnkeditor.push(K.create('textarea[id="' + $(this).attr("jnk_id") + '"]', jnk_config));

    });
  });
});